package com.aaa.proxy;

import javafx.beans.InvalidationListener;
import javafx.beans.Observable;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Date;

/**
 * @author ：zhouhangyong
 * @date ：Created in 2022/6/15 9:35
 * @description：字节码增强器工具类
 * @modified By：
 * @version:
 */
public class ProxyService implements InvocationHandler {
    private Object targetObj;
    public Object getTargetObj(Object classObj){
        targetObj = classObj;
        Object proxyInstance = Proxy.newProxyInstance(targetObj.getClass().getClassLoader(), targetObj.getClass().getInterfaces(), this);
        return proxyInstance;
    }
    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        System.out.println("动态代理日志："+method.getName()+new Date());
        //执行目标对象中的方法
        Object invoke = method.invoke(targetObj, objects);
        return invoke;
    }
}
